home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).zip
/
MegaDisc 41 (1994-09)(MegaDisc Digital Publishing)(AU)(Disk 2 of 2).adf
/
Programming
/
C_Tute
/
program4.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-27
|
1KB
|
49 lines
/***********************************************************************
* Examples of how to use strings with C.
***********************************************************************/
main()
{
char string1[100],string2[100]; /* 2 string variables. Each can hold 99
characters. */
/*********************/
/* example of strcpy */
/*********************/
strcpy(string1,"simon"); /* OK! */
strcpy(string1,string2); /* OK! */
/* strcpy("simon",string1); ILLEGAL!! */
/* strcpy(string1,'J'); ILLEGAL!! You can't copy a character into a string */
/*********************/
/* example of strcat */
/*********************/
strcat(string1,string2); /* attach string2 to string 1 */
strcat(string1,"!!"); /* OK! */
/* strcat("!!",string1); ILLEGAL!! */
/* strcat(string1,'J'); ILLEGAL!! You can't attach a character to a string */
/*********************/
/* example of strcmp */
/*********************/
if( strcmp(string1,string2)==0 )
{
printf("Both strings are equal!\n");
}
else
{
printf("Strings are not equal!\n");
}
}